<?php 
include("common.php");
$search='';
$key=isset($_GET['key'])?$_GET['key']:'';
if($key!=''){
	$search.= " where book_name like '%".$key."%'";
}
    $Page_size=10; 
    $sql = "select * from book ".$search." order by id asc";
	$result = mysql_query($sql);
	$count = mysql_num_rows($result); 
$page_count = ceil($count/$Page_size); 
$init=1; 
$page_len=7; 
$max_p=$page_count; 
$pages=$page_count;
	$rows = @mysql_num_rows($result);	

	if(isset($_GET['action']) && $_GET['action']=='delete'){
	    $sql = "delete from book where id =".$_GET['id']."";
		$result = mysql_query($sql);
		$rows=@mysql_affected_rows();
		if($rows<1){
			echo "<script>alert('删除失败！');window.location.href='book.php';</script>";
		}else{
			echo "<script>alert('删除成功！');window.location.href='book.php';</script>";
		}
	}

?>

 <div class="fr righter">
		  <div class="title">
		    <h1 align="center">查询图书信息</h1>
	      </div>
		  
		  <div class="search" style=" margin-left:30px;">
			  <form action="#" method="get" class="fl">
					<input type="text" name="key" value="<?php echo $key ?>"/>
					<input type="submit" value="查询图书">
			  <a href="index.php">返回首页</a>
			  </form>
			  
		  </div>

		  <table class="xx" width="96%" align="center">
			  <tr>
					  <th width="82">图书编号</th>
				  <th width="82">图书名称</th>
				  <th width="82">价格</th>
				  <th width="82">作者</th>
				  <th width="109">出版社</th>
                  <th width="109">添加时间</th>
			  </tr>
			  <?php
			  while($book=mysql_fetch_array($result)){
				echo "<tr>";
				echo '<td>'.$book['book_id'].'</td>';
				echo '<td>'.$book['book_name'].'</td>';
				echo '<td>'.$book['price'].'</td>';
				echo '<td>'.$book['author'].'</td>';
				echo '<td>'.$book['Press'].'</td>';
				echo '<td>'.$book['addate'].'</td>';
				echo "</tr>";
		      }
			  ?>
		  </table>

	  </div>
  </div>
  
 </body>
</html>
 



